/**
 * Copyright 2018 orivil.com. All rights reserved.
 * Use of this source code is governed by a MIT-style
 * license that can be found at https://mit-license.org.
 */

package actions

import (
	"gitee.com/tugoer/orivil/mux"
	"io/ioutil"
	"net/http"
	"gitee.com/tugoer/wechat-share/code/api/tags"
)

var adminDir = "admin"

var ipAddress = getIPAddress()

func getIPAddress() string {
	resp, err := http.Get("http://myexternalip.com/raw")
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	content, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	return string(content)
}

var Html  = []*mux.Action{
	{
		Name: "Admin WeChat Html",
		Method: "GET",
		Route: "/admin/wechat",
		Handler: func(ctx *mux.Context) {
			ctx.VDir(adminDir).View("layout", "wechat").With("ip", ipAddress)
		},
		ApiDoc:&mux.ApiDoc{
			Tags: []string{tags.AdminHtml},
		},
	},
	{
		Name: "Admin Article Html",
		Method: "GET",
		Route: "/admin/article",
		Handler: func(ctx *mux.Context) {
			ctx.VDir(adminDir).View("layout", "article")
		},
		ApiDoc:&mux.ApiDoc{
			Tags: []string{tags.AdminHtml},
		},
	},
	{
		Name: "Admin Redirect List Html",
		Method: "GET",
		Route: "/admin/redirect",
		Handler: func(ctx *mux.Context) {
			ctx.VDir(adminDir).View("layout", "redirect")
		},
		ApiDoc:&mux.ApiDoc{
			Tags: []string{tags.AdminHtml},
		},
	},
	{
		Name: "Admin Channel Html",
		Method: "GET",
		Route: "/admin/channel",
		Handler: func(ctx *mux.Context) {
			ctx.VDir(adminDir).View("layout", "channel")
		},
		ApiDoc:&mux.ApiDoc{
			Tags: []string{tags.AdminHtml},
		},
	},
}
